<?php

namespace Frieza\Modules\Oauthadmin\Controllers;

use App\Http\Controllers\Controller;
use App\Pockets\GridDataModel as pGridDataModel;
use Doraemon\model\MemberUnregister;
use Doraemon\model\AdminUsers;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets\Tab;
use Illuminate\Http\Request;

//UnregisterDealedListController 查看已注销用户的类
class UnregisterDealedListController extends Controller
{
    public function index(Request $request, Content $content){

        $page = $request->input("page", 1);
        $pageSize = $request->input("per_page", 20);

        $search = $request->all();

        $nike = $search['nick'] ?: '';

        $uptimeStart = strtotime($search['uptime']['start'])?: '';
        $uptimeEnd = strtotime($search['uptime']['end'])?: '';

        $unregisttimeStart = strtotime($search['unregisttime']['start']) ?: '';
        $unregisttimeEnd = strtotime($search['unregisttime']['end'])?: '';

        $status = MemberUnregister::STATUS_DELETE;
        $infos = MemberUnregister::getUnregisterList($status, $page, $pageSize,$nike,$uptimeStart,$uptimeEnd,$unregisttimeStart,$unregisttimeEnd);
        $counts = MemberUnregister::countUnregister($status);

        $gridModel = new pGridDataModel($infos, $counts, ['perPage' => $pageSize]);
        $listGrid = Admin::grid($gridModel, function(Grid $grid){

//            $grid->disableFilter();
            $grid->disableCreateButton();
            $grid->disableExport();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->disableColumnSelector();

            $grid->filter(function ($filter) {
                $filter->disableIdFilter();

                $filter->column(8, function ($filter){
                    $filter->equal('nick', '昵称')->placeholder("请输入昵称");
                });

                $filter->column(12, function ($filter) {
                    $filter->between("uptime", "申请注销日期")->datetime();
                });

                $filter->column(12, function ($filter) {
                    $filter->between("unregisttime", "确认注销日期")->datetime();
                });

                $filter->expand();
            });

            $grid->column("uid")->display(function() {
                return "<a href='/admin/user/Detail/$this->uid' target='_blank' >".$this->uid."</a>";
            })->width(100);;
            $grid->column("nick", "昵称");
            $grid->column("uptime", "申请注销日期")->display(function (){
                return date("Y-m-d H:i:s", $this->uptime);
            });
            $grid->column("unregisttime", "确认注销日期")->display(function (){
                return date("Y-m-d H:i:s", $this->unregisttime);
            });
            $grid->column("operater", "操作人")->display(function(){
                if ($this->operater == 0) {
                    return "系统操作";
                }

                $admUser = AdminUsers::getUsernameByID($this->operater);

                return $admUser;

            });
        });
        $tab = new Tab();
        $tab->add("查看已注销用户", $listGrid->render());
        $content->row($tab);
        return $content
            ->header("注销账号")
            ->breadcrumb(["text" => "查看已注销用户"]);

    }


}